import React, { useEffect,useState,useRef } from 'react'
import { Toast, NavBar } from 'react-vant';
import s from './style.module.less'
import { useNavigate,useLocation } from 'react-router-dom';
import axios from '@/utils/axios.js'
import { useStore, observer } from '@/store'
let count 
let SetInterval
export default function goToMessageContent() {
  const { homeStore } = useStore()
  const location = useLocation()
  const { userStore } = useStore()
  const info = location?.state?.data?.info
  const [houseArr, sethouseArr] = useState([])
  const navigate = useNavigate()
  const goToHome = ()=>{
    navigate('/')
  }
  const onhandleClick = (item)=>{
    return function (params) {
      axios.post('/plots/getplotsNamebyId',{
        plotId:item.plotId
      }).then((res)=>{
        if (res) {
          console.log(res,'小区name');
        const itemInfo = {
          ...item,
          poltName:res.data.data
        }
        localStorage.setItem('houseInfo',JSON.stringify(itemInfo))
        homeStore.setHouseInfo(itemInfo)
        navigate('/housedetail')
        }
      })

    }

}
  useEffect(() => {
    // console.log(userStore?.myId,'userStore?.id');
    // console.log(info,'info');
    axios.post('/user/getOnelike',{
      userId:userStore?.myId
    }).then((result)=>{
      if (result.data.data.length > 0) {
        axios.post('/house/getHouseById',{
          Ids:result.data.data
        }).then((res)=>{
          if (res.data.data.length > 0) {
            sethouseArr(JSON.parse(JSON.stringify(res.data.data)))
            console.log('走这里没',res.data.data);
          }
        })
      }
    })
    
  }, [],()=>{
  })

  return (
    <div className={s.main}>
      <div className={s.top}>
        我的关注
      </div>
      <div id='scrollDom' className={s.outerDiv}>
          <div className={s.mainContent}>
            {
              houseArr.map((item)=>{
                return (
                  <div onClick={onhandleClick(item)} className={s.Content}>
                    <div className={s.left}>
                      <img className={s.leftImg} src={item.img} alt="" />
                    </div>
                    <div className={s.right}>
                      <div className='text-xl'>{`整租-${item.name} 户型${item.Housetype}`}</div>
                      <div>{item.UsableArea}m²｜{item.orientation}</div>
                      <div className={s.rent}>{item.rent}元/月</div>
                      <div className={s.addLike}>
                        近7天新增1人关注
                      </div>
                    </div>
                  </div>
                )
              })
            }
            <div className={s.noMore}>
              没有更多数据
            </div>
          </div>
      </div>
    </div>
  )
}

